<template>

    <el-row style="margin-top: 5%;margin-left: 10%">
        <el-form label-width="120px" v-model="userConfiguration">
            <el-form-item label="新ip登录时:">
                <el-select placeholder="选择一个配置" v-model="userConfiguration.newIpLoginOperation">
                    <el-option label="无操作" :value="0"/>
                    <el-option label="发邮件提醒我" :value="1"/>
                    <el-option label="使用邮件验证码登录" :value="2"/>
                </el-select>
            </el-form-item>
            <el-form-item label="当有人@我时:">
                <el-select placeholder="选择一个配置" v-model="userConfiguration.callMeOperation">
                    <el-option label="无操作" :value="0" />
                    <el-option label="站内消息" :value="1" />
                    <el-option label="站内消息和发邮件提醒我" :value="2" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="updateUserConfiguration">修改</el-button>
            </el-form-item>
        </el-form>
    </el-row>

</template>
<script>

import {reactive, onMounted} from "vue";
import RequestUtil from "@/utils/RequestUtil";
import InfoUtil from "@/utils/InfoUtil";

export default {
    setup() {
        onMounted(() => {
            RequestUtil.sendGetRequest("/userConfiguration/get", null).then(
                (res) => {
                    if (res.code !== 200) {
                        InfoUtil.warning(res.message)
                        return
                    }
                    userConfiguration.callMeOperation = res.data.callMeOperation;
                    userConfiguration.newIpLoginOperation = res.data.newIpLoginOperation
                }
            )
        })
        const userConfiguration = reactive({
            //新ip登录时操作
            newIpLoginOperation: 0,
            //@我时操作
            callMeOperation: 0
        })

        const updateUserConfiguration = () => {
            RequestUtil.sendPostRequest("/userConfiguration/update",userConfiguration).then(
                (res)=>{
                    if(res.code!==200){
                        InfoUtil.warning(res.message);
                        return
                    }
                    InfoUtil.success(res.message);
                },
                (err)=>{
                    InfoUtil.error("发送修改请求失败")
                }
            )


        }
        return {
            userConfiguration,
            updateUserConfiguration
        }
    }

}
</script>
<style scoped>


</style>